<!-- 延度 -->
<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="show ? rowObj.T1 : rowObj.F1" :xs="show ? rowObj.T2 : rowObj.F2">
        <workSiteLeft ref="workSiteLeft" :show="show" @showLeft="showLeft" @queryVal="queryVal" />
      </el-col>
      <el-col :span="show ? rowObj.T3 : rowObj.F3" :xs="show ? rowObj.T4 : rowObj.F4">
        <el-form :model="queryParams" ref="queryForm" size="mini" :inline="true" v-show="showSearch">
          <!-- <el-form-item label="工地名称" prop="baseCode">
            <el-select v-model="queryParams.baseCode" clearable size="mini" placeholder="请选择工地名称">
              <el-option v-for="item in constructionList" :key="item.code" :label="item.name" :value="item.code"></el-option>
            </el-select>
          </el-form-item> -->
          <el-button style="margin-right: 6px" size="mini" :icon="show ? 'el-icon-s-fold' : 'el-icon-s-unfold'" circle @click="showLeft(show)"></el-button>
          <!-- <el-form-item label="试验设备" prop="deviceId">
            <el-select v-model="queryParams.deviceId" clearable size="mini" placeholder="请选择试验设备">
              <el-option v-for="item in equipmentList" :key="item.id" :label="item.name + ' ' + item.model" :value="item.id"></el-option>
            </el-select>
          </el-form-item> -->
          <el-form-item label="关联状态" prop="relevance">
            <el-select style="width: 100px" v-model="queryParams.relevance" clearable size="mini" placeholder="请选择">
              <el-option v-for="item in stateList" :key="item.id" :label="item.name" :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="是否合格" prop="eligible">
            <el-select style="width: 100px" v-model="queryParams.eligible" clearable size="mini" placeholder="请选择">
              <el-option v-for="item in eligibleList" :key="item.id" :label="item.name" :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="试验时间">
            <deatetime ref="deatetime" v-model="queryParams.time"> </deatetime>
          </el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery" v-hasPermi="['laboratoryManage:ductilityData:query']">搜索</el-button>
          <!-- <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button> --> 
        </el-form>
        <el-table border v-loading="loading" :data="cementDataList" size="mini">
          <!-- <el-table-column label="所属单位" align="center" prop="deptName" show-overflow-tooltip width="115"/> -->
          <el-table-column label="所属试验室" align="center" prop="laboratoryName" show-overflow-tooltip min-width="90" />
          <el-table-column label="设备名称" align="center" prop="deviceName" show-overflow-tooltip min-width="150" />
          <el-table-column label="型号/规格" align="center" prop="model" show-overflow-tooltip min-width="80" />
          <el-table-column label="样品名称" align="center" min-width="80" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ scope.row.sysl || "-" }}</span>
            </template>
          </el-table-column>
          <el-table-column label="技术要求" align="center" min-width="80" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ scope.row.sysl || "-" }}</span>
            </template>
          </el-table-column>
          <el-table-column label="位移量(mm)" align="center" min-width="95">
            <template slot-scope="scope">
              <span>{{ scope.row.length1 || "-" }}</span>
            </template>
          </el-table-column>
          <el-table-column label="位移量(mm)" align="center" min-width="95">
            <template slot-scope="scope">
              <span>{{ scope.row.length2 || "-" }}</span>
            </template>
          </el-table-column>
          <el-table-column label="位移量(mm)" align="center" min-width="95">
            <template slot-scope="scope">
              <span>{{ scope.row.length3 || "-" }}</span>
            </template>
          </el-table-column>
          <el-table-column label="延伸速率(mm/min)" align="center" min-width="135">
            <template slot-scope="scope">
              <span>{{ scope.row.speed1 || "-" }}</span>
            </template>
          </el-table-column>
          <el-table-column label="延伸速率(mm/min)" align="center" min-width="135">
            <template slot-scope="scope">
              <span>{{ scope.row.speed2 || "-" }}</span>
            </template>
          </el-table-column>
          <el-table-column label="当前温度(℃)" align="center" min-width="95">
            <template slot-scope="scope">
              <span>{{ scope.row.currTemp || "-" }}</span>
            </template>
          </el-table-column>
          <el-table-column label="设定温度值(℃)" align="center" min-width="110">
            <template slot-scope="scope">
              <span>{{ scope.row.setTemp || "-" }}</span>
            </template>
          </el-table-column>
          <el-table-column label="创建时间" align="center" width="135">
            <template slot-scope="scope">
              <span>{{ scope.row.createTime || "-" }}</span>
            </template>
          </el-table-column>

          <el-table-column fixed="right" label="操作" align="center" class-name="small-padding fixed-width" width="75">
            <template slot-scope="scope">
              <el-button size="mini" type="text" @click="handleDetails(scope.row)" v-hasPermi="['laboratoryManage:ductilityData:details']">查看详情</el-button>
              <!-- <el-button size="mini" type="text" @click="handleDetails(scope.row)" >绑定样品</el-button> -->
            </template>
          </el-table-column>
        </el-table>

        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
      </el-col>
    </el-row>
    <!-- 详情   -->
    <el-dialog title="试验实时数据" :visible.sync="rowDetailsDialog" width="80%">
      <el-table border v-loading="loadingTwo" :data="detailsList" size="mini">
        <el-table-column label="序号" type="index" align="center" width="50" />
        <el-table-column label="设备名称" align="center" min-width="150" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{ scope.row.deviceName || "-" }}</span>
          </template>
        </el-table-column>
        <el-table-column label="型号/规格" align="center" min-width="80" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{ scope.row.model || "-" }}</span>
          </template>
        </el-table-column>
        <el-table-column label="样品名称" align="center" min-width="80" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{ scope.row.ypmc || "-" }}</span>
          </template>
        </el-table-column>
        <el-table-column label="数据标志" align="center" min-width="90" show-overflow-tooltip>
          <template slot-scope="scope">
            <el-tag v-if="scope.row.description != '无效数据'">{{
              scope.row.description
            }}</el-tag>
            <el-tag type="danger" v-else>{{ scope.row.description }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="位移量(mm)" align="center" min-width="95">
          <template slot-scope="scope">
            <span>{{ scope.row.length1 || "-" }}</span>
          </template>
        </el-table-column>
        <el-table-column label="位移量(mm)" align="center" min-width="95">
          <template slot-scope="scope">
            <span>{{ scope.row.length2 || "-" }}</span>
          </template>
        </el-table-column>
        <el-table-column label="位移量(mm)" align="center" min-width="95">
          <template slot-scope="scope">
            <span>{{ scope.row.length3 || "-" }}</span>
          </template>
        </el-table-column>
        <el-table-column label="延伸速率(mm/min)" align="center" min-width="135">
          <template slot-scope="scope">
            <span>{{ scope.row.speed1 || "-" }}</span>
          </template>
        </el-table-column>
        <el-table-column label="延伸速率(mm/min)" align="center" min-width="135">
          <template slot-scope="scope">
            <span>{{ scope.row.speed2 || "-" }}</span>
          </template>
        </el-table-column>
        <el-table-column label="当前温度(℃)" align="center" min-width="100">
          <template slot-scope="scope">
            <span>{{ scope.row.currTemp || "-" }}</span>
          </template>
        </el-table-column>
        <el-table-column label="设定温度值(℃)" align="center" min-width="110">
          <template slot-scope="scope">
            <span>{{ scope.row.setTemp || "-" }}</span>
          </template>
        </el-table-column>

        <el-table-column label="创建时间" align="center" width="135">
          <template slot-scope="scope">
            <span>{{ scope.row.createTime || "-" }}</span>
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="totalTwo > 0" :total="totalTwo" :page.sync="queryParamsTwo.pageNum"
        :limit.sync="queryParamsTwo.pageSize" @pagination="getDetailsList" />
      <span slot="footer" class="dialog-footer">
        <el-button @click="rowDetailsDialog = false" size="mini">取 消</el-button>
      </span>
    </el-dialog>

    <!-- 力值曲线 -->
    <el-dialog title="力值曲线" :visible.sync="forceCurve" width="80%">
      <div class="chartBox">
        <div id="dayChart" style="`width: 100%;height: 100%;transform-origin: 0 0;`"></div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="forceCurve = false" size="mini">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import * as echarts from "echarts";
require("echarts/theme/macarons"); // echarts theme
import { deptList, laboratoryDeviceLIist } from "@/api/common/common";
import {
  ductilityDataList,
  ductilityDatalDetails,
} from "@/api/laboratoryManage/ductilityData";
import deatetime from "@/components/Datetime";
import workSiteLeft from "@/views/components/workSiteLeft";
export default {
  name: "ductilityData", //延度数据
  data() {
    return {
      eligibleList: [
        { id: "0", name: "不合格" },
        { id: "1", name: "合格" },
      ],
      stateList: [
        { id: "0", name: "未关联" },
        { id: "1", name: "已关联" },
      ],
      show: true,
      rowObj: {
        T1: 3,
        T2: 24,
        T3: 21,
        T4: 24,
        F1: 0,
        F2: 0,
        F3: 24,
        F4: 24,
      },
      equipmentList: [],
      ysgcsj: null,
      dayChart: null,
      forceCurve: false,
      rowId: "",
      detailsList: [], //详情列表
      queryParamsTwo: {
        pageNum: 1,
        pageSize: 10,
      },
      totalTwo: 0,
      loadingTwo: false,
      constructionList: [], //工地列表
      rowDetailsDialog: false,
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 水稳拌合站数据表格数据
      cementDataList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
    };
  },
  components: {
    deatetime,
    workSiteLeft,
  },
  created() {
    //this.getEquipmentList();

    // this.getProjectList();

    this.getList();
  },
  methods: {
    /** 查询工地列表 */
    getProjectList() {
      deptList().then((res) => {
        this.constructionList = res || [];
      });
    },
    /** 查询试验设备列表 */
    getEquipmentList() {
      laboratoryDeviceLIist({
        name: "延伸度",
      }).then((res) => {
        this.equipmentList = res.data;
      });
    },
    /** 查询数据列表 */
    getList() {
      this.loading = true;
      ductilityDataList(this.queryParams).then((response) => {
        this.cementDataList = response.data.records;
        this.total = response.data.total;
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams = this.getSearchParams();
      this.queryParams.pageNum = 1;
      this.getList();
    },
    getSearchParams() {
      const params = {};
      for (const key in this.queryParams) {
        if (key === "time") {
          const time = this.queryParams[key];
          if (time && time.length === 2) {
            params.startTime = time[0];
            params.endTime = time[1];
          }
        } else {
          params[key] = this.queryParams[key];
        }
      }
      return params;
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.$refs.workSiteLeft.resetQuery();
      this.queryParams.id = "";
      this.$refs.deatetime.startTime = null;
      this.$refs.deatetime.endTime = null;
      this.queryParams.time = [];
      this.queryParams.startTime = "";
      this.queryParams.endTime = "";
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleDetails(row) {
      this.rowId = row.id;
      this.queryParamsTwo.pageNum = 1;
      this.queryParamsTwo.pageSize = 10;
      ductilityDatalDetails({
        ...this.queryParamsTwo,
        resId: row.id,
      }).then((res) => {
        console.log(res);
        this.detailsList = res.data.records;
        this.totalTwo = res.data.total;
        this.rowDetailsDialog = true;
      });
    },
    getDetailsList() {
      this.loadingTwo = true;
      ductilityDatalDetails({ ...this.queryParamsTwo, resId: this.rowId }).then(
        (response) => {
          this.detailsList = response.data.records;
          this.totalTwo = response.data.total;
          this.loadingTwo = false;
        }
      );
    },
    handleClose() {
      this.$confirm("确认关闭？")
        .then((_) => {
          F;
          done();
        })
        .catch((_) => { });
    },
    handleForceCurve(row) {
      this.forceCurve = true;
      this.ysgcsj = row.ysgcsj;
      let title = "压力机力值曲线";
      if (document.getElementById("dayChart")) {
        this.createDayChart(title, row.ysgcsj);
      } else {
        this.$nextTick(() => {
          this.createDayChart(title, row.ysgcsj);
        });
      }
    },
    createDayChart(title, data) {
      if (null == this.dayChart) {
        // this.dayChart = this.$echarts.init(document.getElementById('dayChart'));
        this.dayChart = echarts.init(document.getElementById("dayChart"));
      } else {
        this.dayChart.clear();
      }
      let xData = [];
      let sData = [];
      if (!!data) {
        let array = data.split(";");
        array.forEach((item) => {
          let dataItem = item.split(",");
          xData.push(dataItem[0]);
          sData.push(dataItem[1]);
        });
      }
      let option = this.getLineOption(title, "时间(秒)", xData, sData);
      this.dayChart.setOption(option);
    },
    /**
     * 获取图表配置信息
     */
    getLineOption(title, xName, xData, sData) {
      let option = {
        title: {
          text: title,
          textStyle: {
            padingLeft: 100,
          },
        },
        tooltip: {
          trigger: "axis",
        },
        toolbox: {
          feature: {
            saveAsImage: {},
          },
        },
        xAxis: {
          name: xName,
          data: xData,
          axisLine: { onZero: true },
          splitLine: { show: false },
          splitArea: { show: false },
          axisLabel: {
            rotate: 45,
            formatter: (value, index) => {
              return value + "秒";
            },
          },
        },
        yAxis: {
          name: "力值(kN)",
          axisLabel: {
            formatter: (value, index) => {
              if (index == 0) {
                return "";
              }
              return value;
            },
          },
        },
        grid: {
          top: 60,
          bottom: 100,
          left: 60,
          right: 60,
        },
        series: [
          {
            data: sData,
            type: "line",
            smooth: true,
            itemStyle: {
              color: "#409EFF",
            },
            areaStyle: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {
                  offset: 0,
                  color: "#409EFF",
                },
                {
                  offset: 1,
                  color: "rgba(64,158,255,0)",
                },
              ]),
            },
          },
        ],
      };
      return option;
    },
    showLeft(show) {
      this.show = !show;
    },
    queryVal(val) {
      this.queryParams.id = val.id;
      this.handleQuery();
    },
  },
};
</script>
<style scoped lang="scss">
.app-ductilityData {

  // padding-top: 16px;
  // user-select: none;
  .chartBox {
    height: 350px;
    width: 100%;
    position: relative;
  }

  .chartBoxHeight {
    height: 400px;
    width: 100%;
    position: relative;
  }

  .chartSearch {
    position: absolute;
    top: 0px;
    right: 60px;
  }
}
</style>

